//合并接口
interface Box{
    height:number;
    width:number;
}

interface Box{
    scale:number;
}
let box:Box={height:4,width:6,scale:23}

//接口函数声明合并
interface Document{
    CreateElement1(tagName:any):Element
}

interface Document{
    CreateElement1(tagName:"div"):HTMLDivElement
}
interface Document{
    CreateElement1(tagName:string):HTMLDivElement
    CreateElement1(tagName:"canvas"):HTMLCanvasElement
}
//合并后的Document是
// interface Document {
//     createElement(tagName: "canvas"): HTMLCanvasElement;
//     createElement(tagName: "div"): HTMLDivElement;
//     createElement(tagName: string): HTMLElement;
//     createElement(tagName: any): Element;
// }
// let s:Document;
// let tag:HTMLDivElement= s.CreateElement1("div")


//合并命名空间
namespace Animals{
    export class Zebra{}
}
namespace Animals{
    export interface Legged{numberOfLegs:number}
    export class dog{}
}
//等同于
// namespace Animals {
//     export interface Legged { numberOfLegs: number; }
//     export class Zebra { }
//     export class Dog { }
// }

//命名空间与函数的合并
function buildLabel(name: string): string {
    return buildLabel.prefix + name + buildLabel.suffix;
}

namespace buildLabel {
    export let suffix = "";
    export let prefix = "Hello, ";
}

console.log(buildLabel("Sam Smith"));

// 命名空间可以用来扩展枚举型
enum Color {
    red = 1,
    green = 2,
    blue = 4
}

namespace Color {
    export function mixColor(colorName: string) {
        if (colorName == "yellow") {
            return Color.red + Color.green;
        }
        else if (colorName == "white") {
            return Color.red + Color.green + Color.blue;
        }
        else if (colorName == "magenta") {
            return Color.red + Color.blue;
        }
        else if (colorName == "cyan") {
            return Color.green + Color.blue;
        }
    }
}
//Color.mixColor("yellow")